package com.nextStep.utils;

import java.util.Random;

/**
 * 验证码
 */
public class VeriCode {

    private static VeriCode veriCode = new VeriCode();

    private  VeriCode(){

    }
    //单例
    public static synchronized VeriCode getVeriCode(){
        return veriCode;
    }

    /**
     * 生成验证码
     * 数字+小写字母
     * @return
     */
    public String veriCodeBuild(){
        Random random = new Random();
        int i =4;
        String code = "";
        while(i>0){
            int bl=random.nextInt(2);   //0数字，1字母
            if(bl==0){
                int num = random.nextInt(26)+1;
                while(num == 8 || num ==9 || num == 11 || num ==14){   //排除掉比较难认的字母
                    num = random.nextInt(26)+1;
                }
                char a  = (char) (num+96);
                code+=a;
            }else {
                int num = random.nextInt(10);
                while(num == 0 || num == 1){
                    num = random.nextInt(10);
                }
                code+=num;
            }
            i--;
        }
        return code;
    }
}
